<!DOCTYPE html>
<html>
<head>
    <meta charset="UTF-8">
    <!--edge浏览器H5兼容设置-->
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <!--360浏览器H5兼容设置-->
    <meta name="renderer" content="webkit" />
    <title>器材报废处理管理</title>
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <!--导入核心文件-->
    <script src="../bootstrap3/js/holder.js"></script>
    <link href="../bootstrap3/css/bootstrap.css" rel="stylesheet" type="text/css">
    <script src="../bootstrap3/jquery-1.9.1.min.js"></script>
    <script src="../bootstrap3/js/bootstrap.js"></script>
    <!-- 字体图标 -->
    <link rel="stylesheet" href="../bootstrap3/font-awesome-4.7.0/css/font-awesome.css" />

    <script src="../bootstrap3/js/jquery.cookie.js" type="text/javascript" charset="utf-8"></script>

    <link rel="stylesheet" type="text/css" href="../css/scrap.css"/>

</head>
<body>
<!--网页最上方的留白-->
<header>
    <!-- class.container 容器定位 的作用是进行居中布局 -->
    <div class="container">
        <!-- pull-right 向右对齐  -->
        <span class="pull-right"><small>Sports  Equipment</small> <b>Management</b>System</span>

    </div>
</header>

<!--网页 导航栏 在layout.css 文件中设置背景图片-->
<nav>
    <!-- class.container 容器定位 用于设置内容居中 -->
    <div class="container">
        <h1>
            <b>体育器材管理系统</b> <small>——Design by Z</small>
        </h1>

        <!--导航栏-->
        <div>
            <!-- class="nav navbar-nav" 定义导航条 -->
            <ul class="nav navbar-nav">
                <li><a href="home.html">首页</a></li>
                <li><a id="btn-purchase">查看器材报废历史记录</a></li>


            </ul>
            <!-- class="nav navbar-nav" 定义导航条 向右侧浮动 -->
            <ul class="nav navbar-nav navbar-right">
                <!-- 导航条中的文字使用 class="navbar-text" 样式 -->
                <li><span class="navbar-text"></span></li>
                <li><a id="loginout"><span class="glyphicon glyphicon-off" aria-hidden="true"></span></a></li>
            </ul>
        </div>
        <!-- /导航栏 -->
    </div>
</nav>
<!--主体-->
<section>

    <div class="container">
        <br>    <br>
        <div class="row">
            <div class="col-md-4"></div>
            <div class="col-md-4">

                <!--表单开始-->
                <form id="form-scrap"   class="form-horizontal" role="form">
                    <span>器材报废处理</span> &#12288;&#12288;&#12288;&#12288;
                    <hr>

                    <!--借啥-->
                    <div class="form-group">
                        <label for="selector" class="col-md-3 col-sm-3 control-label">器材名称</label>
                        <div class="col-md-8 col-sm-8" style="margin-top: 8px">
                            <select id="selector">
                                <option>请选择</option>
                            </select>
                        </div>
                    </div>

                    <!--借多少-->
                    <div class="form-group">
                        <label for="enumber" class="col-md-3 col-sm-3 control-label">报废数量</label>
                        <div class="col-md-8 col-sm-8">
                            <input name="enumber" type="text" class="form-control" id="enumber"  placeholder="申请数量(单位:个)">
                        </div>
                    </div>
                    <div class="form-group">
                        <label for="selectorsup" class="col-md-3 col-sm-3 control-label">器材品牌</label>
                        <div class="col-md-8 col-sm-8">
                            <select id="selectorsup" >
                                <option>请选择</option>
                            </select>
                        </div>
                    </div>

                    <!--提交按钮-->
                    <div class="form-group">
                        <label class="col-md-3  col-sm-3 control-label"></label>
                        <div class="col-md-8 col-sm-8">
                            <input type="button" id="btn-scrap" value="提交申请">

                        </div>
                    </div>
                </form>
            </div>
            <div class="col-md-4">


            </div>
        </div>
    </div>

</section>

<!--页脚开始-->
<!--网页底部， class.well 用于设置背景效果-->
<footer class="well">
    <!-- class.container 的作用是进行居中布局 -->
    <div class="container">
        <b>Copyright © 2020 ？？.com All Rights Reserved
            <a href="#">啥也不是</a>
            版权所有
        </b> <span class="pull-right"> <b>Version</b> 1.1.0
      </span>
    </div>
</footer>
<!--页脚结束-->
<script type="text/javascript">
    $(document).ready(function () {
        $.ajax({
            "url":"/users/loginnum",
            "type":"get",
            "dataType":"json",
            success:function (json) {
                console.log(json.data)
                if (json.data!=null){
                    $("input").removeAttr("disabled")
                    $(".navbar-text").text("管理员："+json.data)
                }
            },
            "error":function () {
                $("input").attr("disabled",true)
                $("#ul").prepend($('<li><a href="' +'http://localhost:8080/web/login.html'+ '">'+"登录"+'</a></li>'))
                $(".navbar-text").text(" ")
            }
        })
        $.ajax({
            "url":"/br/selecter",
            "type":"get",
            "dataType":"json",
            success:function (json) {
                console.log(json.data)
                for (var i=0;i<json.data.length;i++){
                    var option='<option>'+json.data[i].ename+'</option>'
                    $("option:eq(i+1)").attr("value",json.data[i].ename)
                    $("#selector").append(option)
                }

            }
        })
        $.ajax({
            "url":"/br/selectersup",
            "type":"get",
            "dataType":"json",
            success:function (json) {
                console.log(json.data)
                for (var i=0;i<json.data.length;i++){
                    var option='<option>'+json.data[i].sup+'</option>'
                    $("option:eq(i+1)").attr("value",json.data[i].sup)
                    $("#selectorsup").append(option)
                }

            }
        })

    })
    $("#loginout").bind('click',function () {
        $.ajax({
            "url":"/users/logininfo",
            "type":"get",
            "dataType":"json",
            success:function (json) {
                if(json.state==2000){
                    window.location.href="login.html"
                }
            },
            "error":function () {

                $(".navbar-text").append($('<a href="' +'http://localhost:8080/web/login.html'+ '">'+"登录"+'</a>'))

            }
        })
    })
    $("#btn-scrap").click(function () {
        console.log($("#enumber").val())
        if ($("#enumber").val()==""){
            alert("器材数量不能为空")
        } if ($("#ename").val()==""){
            alert("器材名称不能为空")
        } if ($("#sup").val()==""){
            alert("器材品牌不能为空")
        }
        $.ajax({
            "url":"/scrap/addScrap",
            "data":{
                ename:$("#selector option:selected").val(),
                enumber:$("#enumber").val(),
                sup:$("#selectorsup option:selected").val()
            },
            "type":"post",
            "dataType":"json",
            "success":function (json) {
                if (json.state == 2000) {
                    var com=confirm("报废登记成功！是否继续？");
                    if (com){
                        window.location.href="scrap.html"
                    }else{
                        window.location.href="scraphistory.html"
                    }
                } else {
                    alert(json.message)
                }
            }
        })
    })


    $("#btn-purchase").bind('click',function (){

      window.location.href="scraphistory.html"

    })

</script>
</body>
</html>